<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='global-property-'>/**
</span> * @ignore
 * undo button
 * @author yiminghe@gmail.com
 */
KISSY.add(&quot;editor/plugin/undo/btn&quot;, function (S, Editor, Button) {

    var UndoBtn = Button.extend({

        __lock: true,

        bindUI: function () {
            var self = this,
                editor = self.get(&quot;editor&quot;);

            self.on(&quot;click&quot;, function () {
                editor.execCommand(&quot;undo&quot;);
            });
            editor.on(&quot;afterUndo afterRedo afterSave&quot;, function (ev) {
                var index = ev.index;
                //有状态可后退
                if (index &gt; 0) {
                    self.set(&quot;disabled&quot;, self.__lock = false);
                } else {
                    self.set(&quot;disabled&quot;, self.__lock = true);
                }
            });
        }
    }, {
        ATTRS: {
            mode: {
                value: Editor.Mode.WYSIWYG_MODE
            },
            disabled: {
                // 默认 disabled
                value: true,
                setter: function (v) {
                    // wysiwyg mode invalid
                    if (this.__lock) {
                        v = true;
                    }
                    return v;
                }
            }
        }
    });


    var RedoBtn = Button.extend({

        __lock: true,

        bindUI: function () {
            var self = this,
                editor = self.get(&quot;editor&quot;);
            self.on(&quot;click&quot;, function () {
                editor.execCommand(&quot;redo&quot;);
            });
            editor.on(&quot;afterUndo afterRedo afterSave&quot;, function (ev) {
                var history = ev.history,
                    index = ev.index;
                //有状态可前进
                if (index &lt; history.length - 1) {
                    self.set(&quot;disabled&quot;, self.__lock = false);
                } else {
                    self.set(&quot;disabled&quot;, self.__lock = true);
                }
            });
        }
    }, {

        ATTRS: {
            mode: {
                value: Editor.Mode.WYSIWYG_MODE
            },
            disabled: {
                // 默认 disabled
                value: true,
                setter: function (v) {
                    // wysiwyg mode invalid
                    if (this.__lock) {
                        v = true;
                    }
                    return v;
                }
            }
        }
    });


    return {
        RedoBtn: RedoBtn,
        UndoBtn: UndoBtn
    };

}, {
    requires: ['editor', '../button']
});</pre>
</body>
</html>
